if (typeof http_url === 'undefined') {
	var http_urla = document.scripts;
	var http_urlb = http_urla[http_urla.length-1].src;
	var http_url = http_urlb.substring(0,http_urlb.lastIndexOf("/")+1);
}

if (typeof plugFileIframeUpload === 'undefined') {
	var plugFileIframeUpload = http_link+'plug/iframeUpload/';
}
(function ($) {
		$.fn.zhlIframeUpload = function (_this,iframeUploadUrl) {
			if(typeof _this == "undefined"){
				alert('启动插件失败，缺少参数');return false;
			}
			var html = '<style>' +
				'#zhl_file_masks {position: fixed;top: 0px;width: 100%;height: 100%;z-index: 999;background: rgba(0, 0, 0, 0.5);}\n' +
				'#zhl_file_box{width: 110px;height: 110px;position: fixed;top: 50%;left: 50%;margin-left: -55px;margin-top: -110px;background: #fff;z-index: 1000;}\n' +
				'#zhl_file_close{cursor: pointer;position: absolute;top: -10px;right: -10px;background: #fff;width: 25px;height: 25px;border: 1px solid #999; border-radius: 20px;font-size: 14px;color: #999;line-height: 25px;text-align: center;}\n' +
				'#zhl_file_iframe{display:none;}\n' +
				'#zhl_file_btn{display:inline-block;width:110px;height:110px;line-height:150px;text-align:center;background:url('+plugFileIframeUpload+'img/fileaddbtn.png) 33px 28px no-repeat;}\n' +
				'#zhl_file_msg{position: absolute;bottom: 5px;left:15px;color: #666;font-size:14px;}';
				html += '</style>';
				html += '<div id="zhl_file_masks"></div>';
				html += '<div id="zhl_file_box">';
				html += '<div id="zhl_file_close">×</div>';
				html += '<iframe name="zhl_file_iframe" id="zhl_file_iframe"></iframe>';
				html += '<form id="zhl_file_form" action="'+iframeUploadUrl+'" method="post" enctype="multipart/form-data" target="zhl_file_iframe" >';
				html += '<input type="hidden" id="zhl_file_selected" name="selected" />';
				html += '<input type="hidden" id="zhl_file_selectval" name="selectval" />';
				html += '<input type="hidden" id="zhl_file_count" name="cut_c" />';
				html += '<input type="file" id="zhl_upload_file_iframe" hidefocus="true" style="display:none" name="filename[]" multiple="true" />';
				html += '<span id="zhl_file_btn" onclick="zhl_upload_file_iframe.click()" ></span>';
				html += '<div id="zhl_file_msg"></div>';
				html += '</form></div>';
			$('body').prepend(html);

			/**
			 * 选择器赋值
			 */
			var selected = _this.attr('class');
			console.log(selected);
			selected = 'iframe_upload';
			console.log(selected);
			var indexs = $("."+selected).index(_this);
			$('#zhl_file_selected').val(selected);
			$('#zhl_file_selectval').val(indexs);

			/**
			 * 隐藏上传控件
			 */
			$('#zhl_file_close').click(function(){
				$('#zhl_file_masks').remove();
				$('#zhl_file_box').remove();
			})

			/**
			 * 选择文件自动上传
			 */
			$("#zhl_upload_file_iframe").change(function(){
				var fileName = $(this).val();
				if(!fileName){
					alert('请选择文件');
				}else{
					let cut_c = _this.attr('cut_c');
					console.log(cut_c);
					$('#zhl_file_count').val(cut_c);
                    console.log(fileName);
				    console.log(fileName.length);
					//if(fileName.length > 10){
					//	alert('不能超过10个文件');
					//}else{
						$('#zhl_file_msg').text('正在上传中…');
						$("#zhl_file_form").submit();
						//////////////
						//cms用户体验
						_this.parents('.form_item').find('.dowload_input_btn').show();
						//////////////
					//}
				}
			});
		};
})(jQuery);